from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-26 14:02:32.095351
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 26, Nov, 2022
Time: 14:02:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.0607
Nobs: 852.000 HQIC: -51.3701
Log likelihood: 11175.1 FPE: 4.04423e-23
AIC: -51.5622 Det(Omega_mle): 3.64105e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299039 0.050291 5.946 0.000
L1.Burgenland 0.109659 0.034571 3.172 0.002
L1.Kärnten -0.106071 0.018414 -5.760 0.000
L1.Niederösterreich 0.210433 0.072268 2.912 0.004
L1.Oberösterreich 0.100523 0.068643 1.464 0.143
L1.Salzburg 0.251680 0.036653 6.867 0.000
L1.Steiermark 0.037244 0.048058 0.775 0.438
L1.Tirol 0.107349 0.038951 2.756 0.006
L1.Vorarlberg -0.059991 0.033578 -1.787 0.074
L1.Wien 0.054388 0.061380 0.886 0.376
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067543 0.103727 0.651 0.515
L1.Burgenland -0.030115 0.071303 -0.422 0.673
L1.Kärnten 0.047683 0.037980 1.255 0.209
L1.Niederösterreich -0.171910 0.149054 -1.153 0.249
L1.Oberösterreich 0.376363 0.141578 2.658 0.008
L1.Salzburg 0.288498 0.075597 3.816 0.000
L1.Steiermark 0.108348 0.099120 1.093 0.274
L1.Tirol 0.316594 0.080337 3.941 0.000
L1.Vorarlberg 0.023262 0.069254 0.336 0.737
L1.Wien -0.019820 0.126598 -0.157 0.876
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197666 0.026040 7.591 0.000
L1.Burgenland 0.092551 0.017900 5.170 0.000
L1.Kärnten -0.008657 0.009535 -0.908 0.364
L1.Niederösterreich 0.268584 0.037420 7.178 0.000
L1.Oberösterreich 0.114783 0.035543 3.229 0.001
L1.Salzburg 0.052692 0.018978 2.776 0.005
L1.Steiermark 0.016566 0.024884 0.666 0.506
L1.Tirol 0.098466 0.020169 4.882 0.000
L1.Vorarlberg 0.056170 0.017386 3.231 0.001
L1.Wien 0.112232 0.031782 3.531 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105127 0.026714 3.935 0.000
L1.Burgenland 0.047336 0.018363 2.578 0.010
L1.Kärnten -0.017354 0.009781 -1.774 0.076
L1.Niederösterreich 0.197035 0.038387 5.133 0.000
L1.Oberösterreich 0.279911 0.036462 7.677 0.000
L1.Salzburg 0.120155 0.019469 6.172 0.000
L1.Steiermark 0.101358 0.025527 3.971 0.000
L1.Tirol 0.123904 0.020690 5.989 0.000
L1.Vorarlberg 0.068917 0.017836 3.864 0.000
L1.Wien -0.027189 0.032604 -0.834 0.404
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130413 0.048349 2.697 0.007
L1.Burgenland -0.049521 0.033236 -1.490 0.136
L1.Kärnten -0.039311 0.017703 -2.221 0.026
L1.Niederösterreich 0.166830 0.069477 2.401 0.016
L1.Oberösterreich 0.141209 0.065993 2.140 0.032
L1.Salzburg 0.284928 0.035237 8.086 0.000
L1.Steiermark 0.032134 0.046202 0.696 0.487
L1.Tirol 0.162701 0.037447 4.345 0.000
L1.Vorarlberg 0.103726 0.032281 3.213 0.001
L1.Wien 0.068522 0.059010 1.161 0.246
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058569 0.038289 1.530 0.126
L1.Burgenland 0.042551 0.026320 1.617 0.106
L1.Kärnten 0.049828 0.014020 3.554 0.000
L1.Niederösterreich 0.227667 0.055020 4.138 0.000
L1.Oberösterreich 0.271673 0.052261 5.198 0.000
L1.Salzburg 0.058157 0.027905 2.084 0.037
L1.Steiermark -0.006843 0.036588 -0.187 0.852
L1.Tirol 0.156111 0.029655 5.264 0.000
L1.Vorarlberg 0.068428 0.025564 2.677 0.007
L1.Wien 0.074429 0.046731 1.593 0.111
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185462 0.045839 4.046 0.000
L1.Burgenland -0.004536 0.031510 -0.144 0.886
L1.Kärnten -0.060854 0.016784 -3.626 0.000
L1.Niederösterreich -0.086817 0.065870 -1.318 0.188
L1.Oberösterreich 0.192230 0.062566 3.072 0.002
L1.Salzburg 0.059657 0.033408 1.786 0.074
L1.Steiermark 0.225689 0.043803 5.152 0.000
L1.Tirol 0.494780 0.035503 13.936 0.000
L1.Vorarlberg 0.047776 0.030605 1.561 0.119
L1.Wien -0.051372 0.055947 -0.918 0.358
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158516 0.052218 3.036 0.002
L1.Burgenland -0.009076 0.035895 -0.253 0.800
L1.Kärnten 0.064819 0.019120 3.390 0.001
L1.Niederösterreich 0.202941 0.075036 2.705 0.007
L1.Oberösterreich -0.067694 0.071273 -0.950 0.342
L1.Salzburg 0.222414 0.038056 5.844 0.000
L1.Steiermark 0.113769 0.049899 2.280 0.023
L1.Tirol 0.084005 0.040443 2.077 0.038
L1.Vorarlberg 0.122291 0.034864 3.508 0.000
L1.Wien 0.109844 0.063731 1.724 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356788 0.030792 11.587 0.000
L1.Burgenland 0.008731 0.021166 0.413 0.680
L1.Kärnten -0.024671 0.011274 -2.188 0.029
L1.Niederösterreich 0.228315 0.044247 5.160 0.000
L1.Oberösterreich 0.157420 0.042028 3.746 0.000
L1.Salzburg 0.053119 0.022441 2.367 0.018
L1.Steiermark -0.018296 0.029424 -0.622 0.534
L1.Tirol 0.117588 0.023848 4.931 0.000
L1.Vorarlberg 0.071917 0.020558 3.498 0.000
L1.Wien 0.050436 0.037581 1.342 0.180
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043870 0.161328 0.192244 0.165678 0.132096 0.124462 0.070128 0.231253
Kärnten 0.043870 1.000000 0.002022 0.131648 0.044857 0.099297 0.427398 -0.050560 0.102120
Niederösterreich 0.161328 0.002022 1.000000 0.344770 0.166600 0.311119 0.128262 0.192356 0.341352
Oberösterreich 0.192244 0.131648 0.344770 1.000000 0.235493 0.340314 0.177483 0.179751 0.275402
Salzburg 0.165678 0.044857 0.166600 0.235493 1.000000 0.153298 0.145332 0.152804 0.140429
Steiermark 0.132096 0.099297 0.311119 0.340314 0.153298 1.000000 0.163271 0.148353 0.092705
Tirol 0.124462 0.427398 0.128262 0.177483 0.145332 0.163271 1.000000 0.122174 0.164148
Vorarlberg 0.070128 -0.050560 0.192356 0.179751 0.152804 0.148353 0.122174 1.000000 0.019884
Wien 0.231253 0.102120 0.341352 0.275402 0.140429 0.092705 0.164148 0.019884 1.000000